# 需要用到SMTPlib模块
# 需要用到email模块
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# 需要登录QQ邮箱
from_addr = "2660500960@qq.com"
# password = 'hcrdnoqqkhlidiai'     # 授权码
password = "jycgqetqfwpvechh"    # 授权码
# password = "jgfkdgxzlmahdija"    # 授权码
# stmp_server = 'smtp.qq.com'
stmp_server = "smtp.qq.com"
# 定义邮件信息
msgRoot = MIMEMultipart("related")   # 实例化邮件对象
msgRoot['From'] = '2660500960@qq.com'
msgRoot['Subject'] = 'web自动化测试'    # 设置邮件标题
msgRoot['To'] = ','.join(["3286106021@qq.com","2660500960@qq.com"])   # 显示收件人邮箱
msgText = MIMEText("web自动化测试报告")  # 设置邮件正文内容
msgRoot.attach(msgText)  # 添加邮件标题
# 输入收件人
# 输入邮件标题
# 输入邮件正文
# 添加附件
att = MIMEText(open("./report/test_report_20200221181611.html",'rb').read(),'base64','utf-8')  # 添加附件
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = "attachment;filename=test_report_20200219222755.html"
msgRoot.attach(att)
server = smtplib.SMTP(stmp_server,25)
# 登录邮箱服务器
server.login(from_addr,password)
# 发送邮件
server.sendmail(from_addr,["3286106021@qq.com","2660500960@qq.com"],msgRoot.as_string())